package com.bdqn.t296.noso.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bdqn.t296.noso.entity.CCashier;
import com.bdqn.t296.noso.entity.Coutpatienttype;
import com.bdqn.t296.noso.entity.ReportVo;
import com.bdqn.t296.noso.service.PricingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 项目划价
 */
@Controller
@RequestMapping("/caoout")
public class pricingController {

    @Autowired
    private PricingService pricingService;

    //进入项目划价页面
    @RequestMapping("/xiang")
    public Object xiang(Model model) {
        return "hospital/pricing";
    }

    //进入药瓶缴费页面
    @RequestMapping("/out")
    public Object look(Model model) {
        return "hospital/drugspay";
    }

    //查询所有项目信息
    @RequestMapping("/selout")
    @ResponseBody
    public Object seldrug(Coutpatienttype coutpatienttype, int current, String projectName) {
        coutpatienttype.setProjectName(projectName);
        Page<Coutpatienttype> page = new Page<Coutpatienttype>(current, 5);
        IPage<Coutpatienttype> selout = pricingService.selout(page, coutpatienttype);
        return selout;
    }

    //查询处方中是否有该项目
    @RequestMapping("/selchuo")
    @ResponseBody
    public Object seslchuo(CCashier cCashier, Integer reid, String mename) {
        cCashier.setReportId(reid);//把用户id存入数据库
        cCashier.setDurgname(mename);//把药品名称存入实体类
        Integer selcadr = pricingService.selchuo(cCashier);
        return selcadr;
    }

    //没有添加处方项目
    @RequestMapping("/addchuo")
    @ResponseBody
    public Object addchuo(CCashier cCashier, Integer ostate) {
        cCashier.setOstate(ostate);
        //向处方添加药品
        Integer addchuo = pricingService.addchuo(cCashier);
        return addchuo;
    }

    /*//如果处方中有该项目修改数量和价钱
    @RequestMapping("/updchuo")
    @ResponseBody
    public Object updchuo(CCashier cCashier, CPharmacy cPharmacy) {
        //修改处方中药品的数量
        Integer updchuo = pricingService.updchuo(cCashier);
        String pharmacyName = cCashier.getDurgname();
        cPharmacy.setPharmacyName(pharmacyName);
        return updchuo;
    }*/

    //删除处方中的项目
    @RequestMapping("/delo")
    @ResponseBody
    public Object del(CCashier cCashier) {
        Integer del = pricingService.delo(cCashier);
        if (del == 0) {
            return "删除失败";
        } else {
            return "删除成功";
        }
    }

    //查询处方的总价钱
    @RequestMapping("/selch")
    @ResponseBody
    public Object selch(CCashier cCashier) {
        Double selch = pricingService.selch(cCashier);
        return selch;
    }

    //缴费成功修改患者状态为已缴费
    @RequestMapping("/shoufei")
    @ResponseBody
    public Object shoufei(ReportVo reportVo) {
        System.out.println("=================");
        Integer shoufei = pricingService.shoufei(reportVo);
        //把挂号费添加到收费表上
        Integer guafei = pricingService.guafei(reportVo);
        return shoufei;
    }
}
